<?php
use yii\helpers\Html;

$asset_v = time();
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
    <meta charset="<?= Yii::$app->charset ?>">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <?= Html::csrfMetaTags() ?>
    <title>登录-<?= Yii::$app->params['site-title']?></title>
    <link rel="stylesheet" href="<?= Yii::$app->params['static_domain']?>plugin/bootstrap/bootstrap.css">
    <link rel="stylesheet" href="<?= Yii::$app->params['static_domain']?>plugin/font-awesome/font-awesome.css">
    <link rel="stylesheet" href="<?= Yii::$app->params['static_domain']?>plugin/bootstrap/bootstrap.css">
    <?= !empty($this->blocks['css_plugin']) ? $this->blocks['css_plugin'] : '' ?>
    <link rel="stylesheet" href="/css/main.css?v=<?= $asset_v?>">
    <link rel="stylesheet" href="/css/style.css?v=<?= $asset_v?>">
    <?= !empty($this->blocks['css']) ? $this->blocks['css'] : '' ?>
    <?php $this->head() ?>
</head>
<body class="login-layout light-login">
<?php $this->beginBody() ?>
<div class="main-container">
    <div class="main-content">
        <div class="row">
            <div class="col-sm-10 col-sm-offset-1">
                <div class="login-container">
                    <div class="center">
                        <h1>
                            <i class="ace-icon fa fa-leaf green"></i>
                            <span class="red"><?= Yii::$app->params['site-name']?></span>
                            <span class="grey">控制台</span>
                        </h1>
                        <h4 class="blue" id="id-company-text">&copy; <?= Yii::$app->params['company']?></h4>
                    </div>

                    <div class="space-6"></div>

                    <div class="position-relative">
                        <?= $this->render('tpls/login/account_login')?>
                        <?= $this->render('tpls/login/seek_passwd')?>
                        <?= $this->render('tpls/login/phone_login')?>
                    </div><!-- /.position-relative -->
                </div>
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.main-content -->
</div><!-- /.main-container -->
<!--[if !IE]> -->
<script src="<?= Yii::$app->params['static_domain']?>plugin/jquery.js"></script>
<!-- <![endif]-->
<!--[if IE]>
<script src="<?= Yii::$app->params['static_domain']?>plugin/jquery2.js"></script>
<![endif]-->
<script src="<?= Yii::$app->params['static_domain']?>plugin/bootstrap/bootstrap.js"></script>
<script src="<?= Yii::$app->params['static_domain']?>plugin/layer/layer.js"></script>
<script src="<?= Yii::$app->params['static_domain']?>plugin/jquery.form.js"></script>
<script src="<?= Yii::$app->params['static_domain']?>plugin/jquery.validate.js"></script>
<script>
    jQuery.validator.addMethod("mobile", function(value, element) {
        var mobile = /^1[1-9]{1}[0-9]{9}$/;
        return this.optional(element) || (mobile.test(value));
    }, "请正确正确的手机号");
    $('#login-form').validate({
        onfocusout: false,
        onkeyup: false,
        focusInvalid: false,
        rules: {
            mobile: {required: true, mobile: true},
            password: {required: true, minlength: 1}
        },
        messages: {
            mobile: {required: '请输入手机号', mobile: '手机号不正确'},
            password: {required: '请输入登录密码', minlength: '登录密码长度介于3-16位之间'}
        },
        invalidHandler: function(form, validator) {
            var errors = validator.numberOfInvalids();
            if (errors) {
                validator.errorList[0].element.focus();
            }
        },
        showErrors:function(errorMap,errorList) {
            if (errorList.length > 0) {
                layer.msg(errorList[0].message, {icon: 5, anim: 6})
            }
        },
        submitHandler: function(form) {
            $(form).ajaxSubmit({
                dataType : "json",
                success: function(res) {
                    if (res.code === 0) {
                        layer.msg(res.msg, {icon:1}, function(){
                            window.location.href = '/';
                        });
                    } else {
                        layer.msg(res.msg, {icon:2});
                    }
                },
                error: function(xhr, status, error) {
                    if(status==='error'){
                        layer.msg('服务器错误', {icon: 2});
                    }
                }
            });
        }
    });
</script>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>